<template>
  <div>
      <el-transfer :titles="title" v-model="value" :data="data"></el-transfer>
        <el-button @click="change" style="margin-left:220px">确定</el-button>
        <el-button @click="cancel">返回</el-button>
  </div>
</template>

<script>
//这个是得到所有的权限
import {throneDistribution} from "../services/ThroneService.js";
// 根据角色ID得到已有的权限
import {getRoleThrone} from '../services/ThroneService.js'
// 返回角色的权限
import {changeThrone} from '../services/ThroneService.js'
export default {
  data() {
    return {
      data: [],
      value: [],
      title: ["未分配权限", "已分配权限"],
      row:''
    };
  },
  async created(){
        this.row = this.$route.params;
        var resp = await throneDistribution();
        var value =await getRoleThrone(this.row.roleId);
        this.value = value.data.list;
        this.data =resp.data.list;
  },
  methods:{
    async change(){
        var value = this.value.toString();
       var resp = await changeThrone(value,this.row.roleId);
       if(resp.data == "true"){
           alert("权限分配成功");
       }else {
           alert("服务器正忙，权限分配失败");
       }
      },
      cancel(){
          this.$router.push({name:"Role"});
      }
  }
};
</script>
